package base

import (
	"fmt"

	"gorm.io/driver/mysql"
	"gorm.io/gorm"
)

type RemoteDianpu struct {
	Uid           string `sql:"uid"`
	Name          string `sql:"name"`
	Location      string `sql:"location"`
	Pname         string `sql:"pname"`
	Cityname      string `sql:"cityname"`
	Adname        string `sql:"adname"`
	Pcode         string `sql:"pcode"`
	Citycode      string `sql:"citycode"`
	Adcode        string `sql:"adcode"`
	Address       string `sql:"address"`
	Business_area string `sql:"business_area"`
	Type          string `sql:"type"`
	Dalei         string `sql:"dalei"`
	Zhonglei      string `sql:"zhonglei"`
	Xiaolei       string `sql:"xiaolei"`
	Tag           string `sql:"tag"`
	Tel           string `sql:"tel"`
	Cost          string `sql:"cost"`
	Rating        string `sql:"rating"`
	Photos        string `sql:"Photos"`
	Is_use        int8   `sql:"Is_use"`
}

type LocalDianpu struct {
	Id            int32  `sql:"id"`
	Cate_id       int32  `sql:"cate_id"`
	Areaid1       int32  `sql:"areaid1"`
	Areaid2       int32  `sql:"areaid2"`
	Areaid3       int32  `sql:"areaid3"`
	Litpic        string `sql:"litpic"`
	Hits          int    `sql:"hits"`
	Is_show       int8   `sql:"is_show"`
	Create_time   int64  `sql:"create_time"`
	Update_time   int64  `sql:"upodate_time"`
	Show_time     int64  `sql:"show_time"`
	Uid           string `sql:"uid"`
	Name          string `sql:"name"`
	Location      string `sql:"location"`
	Pname         string `sql:"pname"`
	Cityname      string `sql:"cityname"`
	Adname        string `sql:"adname"`
	Pcode         string `sql:"pcode"`
	Citycode      string `sql:"citycode"`
	Adcode        string `sql:"adcode"`
	Address       string `sql:"address"`
	Business_area string `sql:"business_area"`
	Type          string `sql:"type"`
	Tag           string `sql:"tag"`
	Tel           string `sql:"tel"`
	Cost          string `sql:"cost"`
	Rating        string `sql:"rating"`
	Photos        string `sql:"Photos"`
	Jieshao       string `sql:"jieshao"`
	Gongjiao      string `sql:"gongjiao"`
	Ditie         string `sql:"ditie"`
	Tingche       string `sql:"tingche"`
	Canting       string `sql:"canting"`
	Jiudian       string `sql:"jiudian"`
	Is_make       int8   `sql:"is_make"`
	First         string `sql:"first"`
}

func DbConnectRemote() (db *gorm.DB, err error) {
	dsn := fmt.Sprintf("%v:%v@tcp(%v:%v)/%v?charset=utf8&parseTime=True&loc=Local", Config.RemoteDb.Username, Config.RemoteDb.Password, Config.RemoteDb.Hostname, Config.RemoteDb.Hostport, Config.RemoteDb.Database)
	db, err = gorm.Open(mysql.Open(dsn), &gorm.Config{})
	return
}

func DbConnectLocal() (db *gorm.DB, err error) {
	dsn := fmt.Sprintf("%v:%v@tcp(%v:%v)/%v?charset=utf8&parseTime=True&loc=Local", Config.LocalDb.Username, Config.LocalDb.Password, Config.LocalDb.Hostname, Config.LocalDb.Hostport, Config.LocalDb.Database)
	db, err = gorm.Open(mysql.Open(dsn), &gorm.Config{})
	return
}
